﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using log4net;
using System.IO;

namespace Intorise.Library.Common
{
    /// <summary>
    ///Class1 的摘要说明
    /// </summary>
    /// <summary>
    /// 类名称：Logs
    /// 内容摘要：数据同步日志。
    /// 目前使用文本文件来记载，每天一个日子文件。
    /// </summary>
    public static class Logs
    {
        static Logs()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory + @"\config\log4net.config";
            log4net.Config.XmlConfigurator.Configure(new FileInfo(path));
        }

        static ILog errorLog = LogManager.GetLogger("MRWEBLogAll");

        /// <summary>
        /// 错误日志对象
        /// </summary>
        static ILog ErrorLog
        {
            get
            {
                return errorLog;
            }
        }


        // 异常处理
        public static void LogException(Exception ex)
        {
            ErrorLog.Error("[Fatal Error]-", ex);
            throw ex;
        }

        public static void HandleException(Exception ex, string message = "")
        {
            ErrorLog.Error("[Fatal Error]-" + message, ex);
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
            if (ex.InnerException != null)
            {
                Console.WriteLine(ex.InnerException.Message);
                Console.WriteLine(ex.InnerException.StackTrace);
            }
        }

        /// <summary>
        /// 写一条日志信息。
        /// </summary>        
        /// <param name="description">描述</param>
        public static void Log(string description)
        {
            errorLog.Info(description);
        }

        /// <summary>
        /// 写一条日志信息。
        /// </summary>        
        /// <param name="description">描述</param>
        public static void DebugLog(string description)
        {
            if (errorLog.IsDebugEnabled)
            {
                errorLog.Debug(description);
            }
        }


    }
}